package dialog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.zx.theline.jclr.JclrActivity;
import com.example.zx.theline.R;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;

import GsonBean.JcxxChakanBean;
import GsonBean.SuccessBean;
import GsonBean.post.TjjdjcdPost;
import Utils.RefreshManager;
import app.MyApplication;
import base.BaseDialog;
import network.NetWorkApi;
import network.ObjectHttpResponseHandler;
import Utils.MyToast;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by zx on 2017/4/13.
 */
//提交监督检查单dialog
public class TjjdjcdDialog extends BaseDialog {

    TextView queding;
    TextView quxiao;
    JcxxChakanBean mJcxxChakanBean;
    TjjdjcdPost mTjjdjcdPost;

    Activity baseActivity;

    public TjjdjcdDialog(Context context, JcxxChakanBean mJcxxChakanBean, Activity baseActivity) {
        super(context);
        this.mJcxxChakanBean = mJcxxChakanBean;
        this.baseActivity = baseActivity;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_tjjdjcd);
        InitView();
        InitData();
        InitListen();
    }

    @Override
    protected void InitView() {
        queding = (TextView) findViewById(R.id.queding);
        quxiao = (TextView) findViewById(R.id.quxiao);
    }

    @Override
    protected void InitData() {

    }

    @Override
    protected void InitListen() {
        quxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TjjdjcdDialog.this.dismiss();
            }
        });

        queding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.ShowWaitDialog(getContext());
                mTjjdjcdPost = new TjjdjcdPost();
                mTjjdjcdPost.setJdjhjcbId(mJcxxChakanBean.getRjdjhjcbInfo().getJdjhjcbId());
                mTjjdjcdPost.setJcbfcrId(mJcxxChakanBean.getRjdjhjcbInfo().getJcbfcrId());
                mTjjdjcdPost.setFldw(mJcxxChakanBean.getRjdjhjcbInfo().getFldw());
                mTjjdjcdPost.setJcbstatus(mJcxxChakanBean.getRjdjhjcbInfo().getJcbstatus());
                //填写整改情况获取，获取zgqk数据
                mTjjdjcdPost.setZgqk(mJcxxChakanBean.getRjdjhjcbInfo().getZgqk());
                mTjjdjcdPost.setXgrId(MyApplication.getmLoginUser().getUserDisplayName());

                //审核单位流转信息list
                List<TjjdjcdPost.LjyyxRjdjhjcbShdw> jcbShdwList = new ArrayList<TjjdjcdPost.LjyyxRjdjhjcbShdw>();
                TjjdjcdPost.LjyyxRjdjhjcbShdw shdw = new TjjdjcdPost.LjyyxRjdjhjcbShdw();
                shdw.setJdjhbBh(mJcxxChakanBean.getRjdjhjcbInfo().getRjdjhbBh());
                shdw.setDwId(MyApplication.getmLoginUser().getUserUnitId());
                shdw.setDwmc(MyApplication.getmLoginUser().getUserUnitName());
                shdw.setShrlogin(MyApplication.getmLoginUser().getUserDisplayName());
                shdw.setShrname(MyApplication.getmLoginUser().getTrueName());
                shdw.setShrphone(MyApplication.getmLoginUser().getUserMobilephone());
                jcbShdwList.add(shdw);
                mTjjdjcdPost.setJcbShdwList(jcbShdwList);

                NetWorkApi.Tjjdjcd(mTjjdjcdPost, new Callback<SuccessBean>() {
                            @Override
                            public void onResponse(Call<SuccessBean> call, Response<SuccessBean> response) {
                                try {
                                    MyApplication.HideWaitDialog();
                                    SuccessBean mBean = response.body();
                                    if (mBean.getMsg().equals("success") && mBean.getCount() != 0) {
                                        MyToast.showToast("提交监督检查单成功");
                                        RefreshManager.Jdjc.RefreshJdjclrxx();
                                        RefreshManager.Jdjc.RefreshJdjcdcl();
                                        RefreshManager.Jdjc.RefreshJdjcycl();
                                        TjjdjcdDialog.this.dismiss();
                                        getContext().startActivity(new Intent(getContext(), JclrActivity.class));
                                    } else {
                                        MyToast.showFail();
                                    }
                                } catch (Exception e) {
                                    MyToast.showFail();
                                }
                                MyApplication.HideWaitDialog();
                            }

                            @Override
                            public void onFailure(Call<SuccessBean> call, Throwable t) {
                                MyToast.showFail();
                            }
                        }
                );
            }
        });
    }


}
